package homework.course.role.state;

import homework.course.Message;
import homework.course.MessageType;
import homework.course.role.Student;

public class DistractedState extends StudentState {

    public DistractedState(Student std) {
        super(std, "走神", "开始走神");
    }

    @Override
    public String speak() {
        String msg = "欸???";
        std.notifyObservers(new Message(msg, MessageType.WORDS));
        return msg;
    }

    @Override
    public void listen(Object obj, String msg) {
        if(Math.round(Math.random()*3) == 0) {
            std.setState(std.getSleepState());
        } else if(Math.round(Math.random()*1) == 0 && msg != null) {
            std.setState(std.getConcentrateState());
        } else if(Math.round(Math.random()*1) == 0) {
            PlayingState playState = (PlayingState) std.getPlayingState();
            if(playState.isForfeited())
                std.notifyObservers(new Message("想玩手机", MessageType.SYSTEM));
            else
                std.setState(std.getPlayingState());
        } else {
            std.notifyObservers(new Message("若有所思", MessageType.SYSTEM));
        }
    }
}
